<?php


namespace App\Model;


class AdminPermission extends Model
{
    protected $hidden = ['created_at','updated_at'];

    protected $appends = ['type_zh'];

    protected $guarded = [];

    public function getTypeZhAttribute()
    {
        return $this->attributes['type'] == 1 ? '菜单' : '按钮';
    }

    public function childCategory()
    {
        return $this->hasMany(AdminPermission::class, 'pid', 'id');
    }

    public function children()
    {
        return $this->childCategory()->with('children');
    }
}